home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_386 / xlispstat / src2.lzh / XLisp-Stat / xsnamelist.c < prev    next >
C/C++ Source or Header  |  1990-10-02  |  9KB  |  290 lines

  1. /* xsnamelist - XLISP interface to IVIEW dynamic graphics package.     */
  2. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  3. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  4. /* You may give out copies of this software; for conditions see the    */
  5. /* file COPYING included with this distribution.                       */
  6.  
  7. #include "xlisp.h"
  8. #include "osdef.h"
  9. #ifdef ANSI
  10. #include "xlproto.h"
  11. #include "xlsproto.h"
  12. #include "iviewproto.h"
  13. #include "Stproto.h"
  14. #else
  15. #include "xlfun.h"
  16. #include "xlsfun.h"
  17. #include "iviewfun.h"
  18. #include "Stfun.h"
  19. #endif ANSI
  20. #include "xlsvar.h"
  21.  
  22. #ifdef ANSI
  23. void list_draw_point(IVIEW_WINDOW,int,PointState);
  24. int list_space(StGWWinInfo *);
  25. #else
  26. void list_draw_point();
  27. int list_space();
  28. #endif ANSI
  29.  
  30. #define LIST_BOTTOM_GAP 3
  31. #define LIST_STRINGS_VISIBLE 15
  32. #define LIST_STRING_TEMPLATE "123456789012345678901234567890"
  33. #define LIST_PAGE_INC 10
  34. #define LIST_CLICK_WIDTH 1
  35. #define LIST_CLICK_HEIGHT 1
  36.  
  37. static int list_space(gwinfo)
  38.     /* char */ StGWWinInfo *gwinfo; /* changed JKL */
  39. {
  40.   return(StGWTextAscent(gwinfo) + StGWTextDescent(gwinfo) + LIST_BOTTOM_GAP);
  41. }
  42.  
  43. /**************************************************************************/
  44. /**                                                                      **/
  45. /**                        List Creation Functions                       **/
  46. /**                                                                      **/
  47. /**************************************************************************/
  48.  
  49. LVAL iview_list_allocate()
  50. {
  51.   LVAL object;
  52.   int width, height, space;
  53.   IVIEW_WINDOW w;
  54.   /* char */ StGWWinInfo *gwinfo; /* changed JKL */
  55.   int show;
  56.  
  57.   object = xlgaobject();
  58.   show = xsboolkey(sk_show, TRUE);
  59.   w = IViewNew(object);
  60.   gwinfo = StGWObWinInfo(object);
  61.   initialize_iview(w, object);
  62.  
  63.   space = list_space(gwinfo);
  64.   width = StGWTextWidth(gwinfo, LIST_STRING_TEMPLATE);
  65.   height = LIST_STRINGS_VISIBLE * space;
  66.   StGWSetSize(gwinfo, width, height, FALSE); 
  67.   StGWSetHasVscroll(gwinfo, TRUE, height);
  68.   StGWSetVscrollIncs(gwinfo, space, LIST_PAGE_INC * space);
  69.   StGrSetClickRange(gwinfo, LIST_CLICK_WIDTH, LIST_CLICK_HEIGHT);
  70.  
  71.   /* use StShowWindow to show (map) window but NOT send :resize or :redraw */
  72.   if (show) StShowWindow(w);
  73.  
  74.   return(object);
  75. }
  76.  
  77. /**************************************************************************/
  78. /**                                                                      **/
  79. /**                            Data Functions                            **/
  80. /**                                                                      **/
  81. /**************************************************************************/
  82.  
  83. LVAL iview_list_add_points()
  84. {
  85.   IVIEW_WINDOW w;
  86.   int old_n, n;
  87.   LVAL object, data;
  88.   int space;
  89.   /* char */ StGWWinInfo *gwinfo; /* changed JKL */
  90.   
  91.   object = xlgaobject();
  92.   w = GETIVIEWADDRESS(object);
  93.   gwinfo = StGWObWinInfo(object);
  94.   if (w == nil || gwinfo == nil) return(NIL);
  95.   
  96.   old_n = IViewNumPoints(w);
  97.   data = xlgetarg();
  98.   internal_iview_add_points(w, object, data);
  99.   n = IViewNumPoints(w);
  100.   
  101.   space = list_space(gwinfo);
  102.   check_add_to_screen(object, 'P', old_n, n, TRUE);
  103.   StGWSetHasVscroll(gwinfo, TRUE, n * space);
  104.   
  105.   return(NIL);
  106. }
  107.  
  108. /**************************************************************************/
  109. /**                                                                      **/
  110. /**                    Drawing and Resizing Functions                    **/
  111. /**                                                                      **/
  112. /**************************************************************************/
  113.  
  114. LVAL iview_list_redraw_content()
  115. {
  116.   int i, n;
  117.   int left, top, width, height;
  118.   PointState state;
  119.   IVIEW_WINDOW w;
  120.   LVAL object;
  121.   /* char */ StGWWinInfo *gwinfo; /* changed JKL */
  122.   
  123.   object = xlgaobject();
  124.   xllastarg();
  125.   
  126.   gwinfo = StGWObWinInfo(object);
  127.   w = GETIVIEWADDRESS(object);
  128.   if (w == nil) return(NIL);
  129.   
  130.   n = IViewNumPoints(w);
  131.   StGWGetViewRect(gwinfo, &left, &top, &width, &height);
  132.   StGWStartBuffering(gwinfo);
  133.   StGWEraseRect(gwinfo, left, top, width, height);
  134.   
  135.   for (i = 0; i < n; i++) {
  136.     state = IViewPointState(w, i);
  137.     if (! IViewPointMasked(w, i) && state != pointInvisible)
  138.       list_draw_point(w, i, state);   
  139.   }
  140.   IViewResetScreenStates(w);
  141.   StGWBufferToScreen(gwinfo, left, top, width, height);
  142.   return(NIL);
  143. }
  144.  
  145. /**************************************************************************/
  146. /**                                                                      **/
  147. /**                           Mouse Functions                            **/
  148. /**                                                                      **/
  149. /**************************************************************************/
  150.  
  151. static void list_draw_point(w, i, state)
  152.     IVIEW_WINDOW w;
  153.     int i;
  154.     PointState state;
  155. {
  156.   int left, top, width, height, space;
  157.   /* int */ ColorCode  color, old_color; /* changed JKL */
  158.   /* char */ StGWWinInfo *gwinfo; /* changed JKL */
  159.  
  160.   gwinfo = IViewWindowWinInfo(w);
  161.  
  162.   StGWGetViewRect(gwinfo, &left, &top, &width, &height);
  163.   space = list_space(gwinfo);
  164.  
  165.   old_color = StGWDrawColor(gwinfo);
  166.   color = IViewPointColor(w, i);
  167.   if (color >= 0) StGWSetDrawColor(gwinfo, color);
  168.   if (state == pointNormal) {
  169.     StGWEraseRect(gwinfo, 0, space * i, width, space);
  170.     StGWDrawString(gwinfo, IViewPointLabel(w, i), LIST_BOTTOM_GAP,
  171.                            (i + 1) * space - LIST_BOTTOM_GAP);
  172.   }
  173.   else {
  174.     StGWPaintRect(gwinfo, 0, space * i, width, space);
  175.     StGWSetDrawColor(gwinfo, StGWBackColor(gwinfo));
  176.     StGWDrawString(gwinfo, IViewPointLabel(w, i), LIST_BOTTOM_GAP,
  177.                            (i + 1) * space - LIST_BOTTOM_GAP);
  178.   }
  179.   StGWSetDrawColor(gwinfo, old_color);
  180.   IViewSetPointScreenState(w, i, state);
  181. }
  182.  
  183. LVAL iview_list_adjust_screen_point()
  184. {
  185.   LVAL object;
  186.   int point;
  187.   IVIEW_WINDOW w;
  188.   PointState state, screen_state;
  189.   
  190.   object = xlgaobject();
  191.   point = getfixnum(xlgafixnum());
  192.   xllastarg();
  193.  
  194.   w = GETIVIEWADDRESS(object);
  195.   if (w == nil) return(NIL);
  196.   
  197.   if (! IViewPointMasked(w, point)) {
  198.     state = IViewPointState(w, point);
  199.     screen_state = IViewPointScreenState(w, point);
  200.     if (state == pointInvisible || screen_state == pointInvisible) {
  201.       StGrSetDirty(StGWObWinInfo(object), TRUE);
  202.     }
  203.     else {
  204.       list_draw_point(w, point, state);
  205.     }  
  206.   }
  207.  
  208.   return(NIL);
  209. }
  210.  
  211. LVAL iview_list_adjust_points_in_rect()
  212. {
  213.   int  i, n, in_rect, space, bottom, /* left, */top, height /*, width*/;
  214.   PointState point_state, state;
  215.   IVIEW_WINDOW w;
  216.   LVAL object;
  217.   /* char */ StGWWinInfo *gwinfo; /* changed JKL */
  218.   
  219.   object = xlgaobject();
  220.   w = GETIVIEWADDRESS(object);
  221.   gwinfo = StGWObWinInfo(object);
  222.   /* left = */getfixnum(xlgafixnum()); /* return value not used JKL */
  223.   top = getfixnum(xlgafixnum());
  224.   /* height = */ getfixnum(xlgafixnum()); /* return value not used JKL */
  225.   height = getfixnum(xlgafixnum());
  226.   state = decode_point_state(xlgetarg());
  227.   xllastarg();
  228.   
  229.   if (w == nil) return(NIL);
  230.  
  231.   IViewCheckLinks(w);
  232.   n = IViewNumPoints(w);
  233.   space = list_space(gwinfo);
  234.   bottom = top + height;
  235.   
  236.   if (IViewMouseMode(w) == brushing) IViewEraseBrush(w);
  237.  
  238.   for (i = 0; i < n; i++) {
  239.     point_state = IViewPointState(w, i);
  240.     if (! IViewPointMasked(w, i) && point_state != pointInvisible) {
  241.       in_rect = (top < (i + 1) * space && bottom > i * space);
  242.       if (in_rect && (int) point_state < (int) state) {
  243.         IViewSetPointState(w, i, state);
  244.       }
  245.       else if (! in_rect 
  246.            && state == pointHilited && point_state == pointHilited) {
  247.         IViewSetPointState(w, i, pointNormal);
  248.       }
  249.     }
  250.   }
  251.   IViewAdjustScreens(w);
  252.   if (IViewMouseMode(w) == brushing) IViewDrawBrush(w);
  253.  
  254.   return(NIL);
  255. }
  256.  
  257. LVAL iview_list_mark_points_in_rect()
  258. {
  259.   int  i, n, in_rect, space, bottom, /*left,*/ top, /*width,*/ height;
  260.   PointState point_state;
  261.   IVIEW_WINDOW w;
  262.   LVAL object;
  263.   StGWWinInfo *gwinfo;
  264.   
  265.   object = xlgaobject();
  266.   w = GETIVIEWADDRESS(object);
  267.   gwinfo = StGWObWinInfo(object);
  268.   /* left = */ getfixnum(xlgafixnum()); /* return value not used JKL */
  269.   top = getfixnum(xlgafixnum());
  270.   /* width = */ getfixnum(xlgafixnum()); /* return value not used JKL */
  271.   height = getfixnum(xlgafixnum());
  272.   xllastarg();
  273.   
  274.   if (w == nil) return(NIL);
  275.  
  276.   n = IViewNumPoints(w);
  277.   space = list_space(gwinfo);
  278.   bottom = top + height;
  279.   
  280.   for (i = 0; i < n; i++) {
  281.     point_state = IViewPointState(w, i);
  282.     if (! IViewPointMasked(w, i) && point_state != pointInvisible) {
  283.       in_rect = (top < (i + 1) * space && bottom > i * space);
  284.       IViewSetPointMark(w, i, in_rect);
  285.     }
  286.   }
  287.  
  288.   return(NIL);
  289. }
  290.